//JSON objects
entry1 = {name:"zhangsan", age:30}
entry2 = {name:"lisi", age:40}
entry3 = {name:"zhouwu", age:50, array: [1, 2, 3, 4]}
entry4 = {name:"wangliu", age:60, nested:{x:1, y:"abc"}}

//insert
db.persons.insert(entry1);
db.persons.insert(entry2);
db.persons.insert(entry3);
db.persons.insert(entry4);

//basic update
db.persons.update({name: "zhangsan"}, {name:"zhangsan", age:50})
db.persons.update({name: "liuba"}, {name:"liuba", age:10})

//upsert
db.persons.update({name: "liuba"}, {name:"liuba", age:10}, {upsert:true})

//increment operation
db.persons.find({age:{$le:40}})
db.persons.update({age:{$lte:70}}, {$inc: {age:5}})

//set operation
db.persons.update({age:{$gte:60}}, {$set:{age:60}})


//multiple update
db.persons.update({age:{$lte:70}}, {$inc: {age:5}}, {multi:true})

//remove field
db.persons.update({name:"zhouwu"}, {$unset: {array: 1}})
db.persons.update({name:"wangliu"}, {$unset: {"nested.x": 1}})
